;; Loading of packages is configure in this file.

(require 'package)
(package-initialize)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)

;; Package loading based on:
;;   http://blog.zhengdong.me/2012/03/14/how-i-manage-emacs-packages
(require 'cl)
;; Guarantee all packages are installed on start
(defvar mk/package-list
  '(
    autopair
    cursor-chg
    deft
    diminish
    expand-region
    fic-mode
    highlight-indentation
    highlight-symbol
    magit
    rainbow-mode
    smex
    undo-tree
    yasnippet
    )
  "List of packages needs to be installed at launch")

(defun mk/package-missing-p (package-list)
  (loop for package in package-list
        when (not (package-installed-p package))
	do (return t)
        finally (return nil)))

(when (mk/package-missing-p mk/package-list)
  ;; Check for new packages (package versions)
  (message "%s" "Get latest versions of all packages...")
  (package-refresh-contents)
  (message "%s" " done.")
  ;; Install the missing packages
  (dolist (package mk/package-list)
    (when (not (package-installed-p package))
      (package-install package))))
